package com.web.server.common.exception;

import org.springframework.http.client.ClientHttpResponse;
import org.springframework.web.client.ResponseErrorHandler;

import java.io.IOException;

/**
 * Created by ZHANGXIANLIANG1 on 2016/3/18.
 */
public class HttpErrorHandle implements ResponseErrorHandler {

    @Override
    public boolean hasError(ClientHttpResponse response) throws IOException {
        return response.getStatusCode().value() != 200;
    }

    @Override
    public void handleError(ClientHttpResponse response) throws IOException {
        byte[] bytes = new byte[response.getBody().available()];
        throw new CrmException(StatusCode.STATUS_REMOTE_HTTP_ERROR, new String(bytes, "utf8"));
    }
}
